server {
    listen 80 default_server;
    server_name www.example.localhost;

    # 基础目录设置
    root /server/public;

    # 日志配置
    access_log /logs/www.example.localhost_access_nginx.log main;
    error_log /logs/www.example.localhost_error_nginx.log;

    # 接口服务代理
    location ~ ^/(api|spi|v1)/ {
        proxy_pass http://mdd-python:9100;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Host $host:$server_port;
        proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        # 响应设置
        add_header X-Cache $upstream_cache_status;
        # 超时设置
        proxy_connect_timeout 30s;
        proxy_send_timeout 30s;
        proxy_read_timeout 7200s;
        # WebSocket支持
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    # 静态资源代理
    location ~ ^/(static|storage)/ {
        try_files $uri =404;
        add_header X-Content-Type-Options "nosniff";
        add_header X-Frame-Options "SAMEORIGIN";
        add_header Cache-Control "public";
        expires 30d;
    }

    # 后台访问入口
    location /admin {
        alias /server/public/admin/;
        index index.html;
        try_files $uri $uri/ /admin/index.html;
        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Content-Type-Options "nosniff";
    }

    # 前台访问入口
    location / {
        alias /server/public/pc/;
        index index.html;
        try_files $uri $uri/ /index.html;
    }

    # favicon
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }
}
